//
// StockBrandCategoryJa.m
// DataCollector
//
// Created by jiro on 12/06/09.
// Copyright 2012 jiro music. All rights reserved.
//

#import "StockBrandCategoryJa.h"

#import "DbConstants.h"

@implementation StockBrandCategoryJa

@synthesize type;
@synthesize name;
@synthesize startCode;
@synthesize endCode;

+ (NSString*) tableName
{
	return kText_StockBrandCategoryJaTable;
}

+ (NSString*) queryCreateTable
{
	NSString* s = [ NSString stringWithFormat: 
		@"create table %@( %@ %@, %@ %@, %@ %@, %@ %@, primary key( type ) );",
			[ StockBrandCategoryJa tableName ],
			kText_Type, kText_Integer,
			kText_StartCode, kText_Text,
			kText_EndCode, kText_Text,
			kText_Name, kText_Text,
			kText_PrimaryKey, kText_Type
		];
	return s;
}

+ (NSString*) queryInsertInitialValues
{
	struct Category
	{
		int code; NSString* startCode; NSString* endCode; NSString* name;
	};

	Category categories[] =
	{
		{ 0, @"1300", @"1399", @"農林水産", },
 		{ 1, @"1500", @"1699", @"鉱業", },
 		{ 2, @"1700", @"1999", @"建設", },
 		{ 3, @"2000", @"2999", @"食品", },
 		{ 4, @"3000", @"3599", @"繊維製品", },
 		{ 5, @"3700", @"3999", @"パルプ・紙", },
 		{ 6, @"4000", @"4999", @"化学・医薬品", },
 		{ 7, @"5000", @"5099", @"石油・石炭", },
 		{ 8, @"5100", @"5199", @"ゴム", },
 		{ 9, @"5200", @"5399", @"窯業", },
 		{ 10, @"5400", @"5699", @"鉄鋼", },
 		{ 11, @"5700", @"5800", @"非鉄金属", },
 		{ 12, @"5900", @"5999", @"金属製品", },
 		{ 13, @"6000", @"6499", @"機械", },
 		{ 14, @"6500", @"6999", @"電気", },
 		{ 15, @"7000", @"7499", @"輸送用機械", },
 		{ 16, @"7700", @"7799", @"精密機械", },
 		{ 17, @"7800", @"7999", @"その他製品", },
 		{ 18, @"8000", @"8299", @"商業", },
 		{ 19, @"8300", @"8599", @"銀行・ノンバンク", },
 		{ 20, @"8600", @"8699", @"証券・証券先物", },
 		{ 21, @"8700", @"8799", @"保険", },
 		{ 22, @"8800", @"8999", @"不動産", },
 		{ 23, @"9000", @"9099", @"陸運", },
 		{ 24, @"9100", @"9199", @"海運", },
 		{ 25, @"9200", @"9299", @"空運", },
 		{ 26, @"9300", @"9399", @"倉庫・運輸", },
 		{ 27, @"9400", @"9499", @"情報通信", },
 		{ 28, @"9500", @"9599", @"電気ガス", },
 		{ 29, @"9600", @"9999", @"サービス", },
	};

	NSString* ret = [ NSString string ];
	for ( int i = 0, count = sizeof( categories ) / sizeof( Category ); i < count; i++ )
	{
		StockBrandCategoryJa* sbc = [ [ StockBrandCategoryJa alloc ] init ];
		Category& category = categories[ i ];

		sbc.type = static_cast< StockBrandCategoryJaType::Type >( category.code );
		sbc.startCode = category.startCode;
		sbc.endCode = category.endCode;
		sbc.name = category.name;

		ret = [ ret stringByAppendingString: [ sbc queryInsertValue ] ];
		if ( i != count - 1 )
		{
			ret  = [ ret stringByAppendingString: @", " ];
		}
	}
	return ret;
}

+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ StockBrandCategoryJa tableName ] ];
	return s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into * values %@;", 
		[ StockBrandCategoryJa tableName ], [ self queryInsertValue ] ];
	return s;
}


- (NSString*) queryInsertValue
{
	NSString* ret = [ NSString stringWithFormat: @"( %d, '%@', '%@', '%@' )", 
		type, startCode, endCode, name ];
	return ret;
}

@end
